package com.boot.utils;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class Result<T> {
    private Integer code;
    private String message;

    private T data;

    public Result() {
    }

    public static <T> Result<T> build(T data) {
        Result<T> result = new Result<>();
        if (data != null) result.data = data;
        return result;
    }

    public static <T> Result<T> build(T data, Integer code, String message) {
        Result<T> result = build(data);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> build(T data, ResultCodeEum resultCodeEum) {
        Result<T> result = build(data);
        result.setCode(resultCodeEum.getCode());
        result.setMessage(resultCodeEum.getMessage());
        return result;
    }

    public static <T> Result<T> ok(T data) {
        return build(data, ResultCodeEum.SUCCESS);
    }
}
